package com.example.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.CompletableFuture;

@Service
public class TaskService {

    @Autowired
    private TimeService timeService;

    public void executeTasks() {
        System.out.println("🚀 开始执行任务...");

        // 执行多个并发任务
        CompletableFuture<Void> task1 = timeService.printCurrentTimeEverySecond(5);
        CompletableFuture<Void> task2 = timeService.countdownTimer(10);
        CompletableFuture<Void> task3 = timeService.printCurrentTimeEverySecond(8);

        // 等待所有任务完成
        CompletableFuture.allOf(task1, task2, task3).join();

        System.out.println("✅ 所有任务执行完成！");
    }

    public void executeSingleTask() {
        System.out.println("🎯 执行单个任务...");
        timeService.countdownTimer(5).join();
    }
}